<?php

namespace app\admin\controller;

class Introduces extends Base
{
    //留学优势列表
    public function introduces_list()
    {
        $in = model('common/Introduces') -> paginate(5);
        $data = [
            'in' => $in
        ];
        $this -> assign($data);
        return view();
    }

    //留学优势添加
    public function introduces_add()
    {
        if (request()->isAjax()){
            $data = input('post.');
            $data['img'] = request() -> file('myFile');
            $result = model('common/Introduces') -> introduces_add($data);
            if ($result == 1){
                $this -> success('添加成功！','admin/introduces/introduces_list');
            } else {
                $this -> error($result);
            }
        }
        return view();
    }

    //留学优势编辑
    public function introduces_edit()
    {
        if (request()->isAjax()){
            $data = input('post.');
            $data['imgs'] = request() -> file('myFile');
            $result = model('common/Introduces') -> introduces_edit($data);
            if ($result == 1){
                $this -> success('更新成功！','admin/introduces/introduces_list');
            } else {
                $this -> error($result);
            }
        }
        $in = model('common/Introduces') -> find(input('id'));
        $data = [
            'in' => $in
        ];
        $this -> assign($data);
        return view();
    }

    //留学优势删除
    public function introduces_del()
    {
        if (request()->isAjax()){
            $result = model('common/Introduces')
                -> find(input('post.id'))
                -> delete();
            if ($result){
                $this -> success('删除成功！','admin/introduces/introduces_list');
            } else {
                $this -> error('删除失败！');
            }
        }
    }
}
